#fileUrl <- "http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt"
#download.file(fileUrl,destfile="./data/earthquakeData.csv")
#dateDownloaded <- date()
#dateDownloaded
#eData <- read.csv("./data/earthquakeData.csv")

basic_summarize_data <- function (data){
  print("####################     DIM       ####################")
  print(dim(data))
  print("####################     NAMES     ####################")
  print(names(data))
  print("####################     CLASSES   ####################")
  print(sapply(data[1,],class))
  print("####################     HEAD      ####################")
  print(head(data))
  print("####################     SUMMARY   ####################")
  print(summary(data))
  print("####################     % UNIQUES vs TOTALES (for factors)   ####################")
  print(unlist(sapply(data, function (x){if(is.factor(x)){round(100*length(unique(x))/length(x), 2)}})))
  print("####################     UNIQUE (for factors)   ####################")
  print(Filter(Negate(is.null),sapply(data, function (x){porc <- length(unique(x))/length(x);if(is.factor(x)){ if(porc< 0.5){unique(x)} else {paste0(round(100*porc,2),"% de factores respecto al total")}}})))
  print("####################     TABLE (for factors)   ####################")
  print(Filter(Negate(is.null),sapply(data, function (x){porc <- length(unique(x))/length(x);if(is.factor(x)){ if(porc< 0.5){table(x)} else {paste0(round(100*porc,2),"% de factores respecto al total")}}})))
  print("####################     % of NAs for numerics   ####################")
  print(unlist(sapply(data, function (x){ if(is.numeric(x)){round(100*sum(is.na(x))/length(x),2)}})))
}

#basic_summarize_data(eData)
#print("####################     QUANTILE (ya esta en el sumario)    ####################")
## otra forma print(quantile(eData$Lat))
## otra forma print(table(eData$Src,eData$Version))
## otra forma print(eData$Lat[1:10] > 40)
## otra forma print(any(eData$Lat[1:10] > 40))
## otra forma print(all(eData$Lat[1:10] > 40))
## otra forma eData[eData$Lat > 0 & eData$Lon > 0,c("Lat","Lon")]
## otra forma eData[eData$Lat > 0 | eData$Lon > 0,c("Lat","Lon")]

#fileUrl1 <- "https://dl.dropbox.com/u/7710864/data/reviews-apr29.csv"
#fileUrl2 <- "https://dl.dropbox.com/u/7710864/data/solutions-apr29.csv"
#download.file(fileUrl1,destfile="./data/reviews.csv")
#download.file(fileUrl2,destfile="./data/solutions.csv")
reviews <- read.csv("./data/reviews.csv"); 
solutions <- read.csv("./data/solutions.csv")
basic_summarize_data(reviews)     
basic_summarize_data(solutions)     
## otra forma table(is.na(reviews$time_left))
#otra forma table(solutions$start, useNA="ifany")
#otra cosa colSums(reviews,na.rm=TRUE)
#otra cosa colMeans(reviews,na.rm=TRUE)
#otra cosa rowMeans(reviews,na.rm=TRUE)
      